package com.example.workoutjournal;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;

public class AddExercise extends Activity {
	private Integer setID;
	private DAO database;
	private String setName;
	
	@SuppressLint("NewApi")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_add_exercise);
		getActionBar().hide();
		Intent intent = getIntent();
	    String setID = intent.getStringExtra("setID");
	    setName = intent.getStringExtra("SET_NAME");
	    
	    this.setID = Integer.parseInt(setID);
	    
		database = new DAO(this);
		database.open();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.add_exercise, menu);
		return true;
	}
	
	public void addExercise(View view){
		EditText exNameText = (EditText) findViewById(R.id.exName);
        String exName = exNameText.getText().toString();
        
        EditText exSeriesText = (EditText) findViewById(R.id.exSeries);
        String exSeriesStr = exSeriesText.getText().toString();
        Integer exSeries = Integer.parseInt(exSeriesStr);
        
        EditText exRepsText = (EditText) findViewById(R.id.exReps);
        String exRepsStr = exRepsText.getText().toString();
        Integer exReps = Integer.parseInt(exRepsStr);
        
        EditText exWeightText = (EditText) findViewById(R.id.exWeight);
        String exWeightStr = exWeightText.getText().toString();
        Integer exWeight = Integer.parseInt(exWeightStr);
        
        Exercise newEx = database.createExercise(exName, exReps, exWeight, exSeries, this.setID);

       	Intent intent = new Intent(this, SetActivity.class);
        intent.putExtra("TOAST_TEXT", "Exercise "+newEx.toString()+" inserted succesfully.");
        intent.putExtra("SET_NAME", setName);
        intent.putExtra(MyExercises.SET_ID, setID.toString());
        database.close();
        startActivity(intent);
	    
	    // Set the text view as the activity layout
        
	}

}
